package com.example.chat.model;

import com.example.chat.type.DataStatusEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;
import java.util.Date;

/**
 * @author pq
 * @date 2022/8/14 0:37
 * @description
 * @modified
 **/
@Data
@Accessors(chain = true)
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@JsonIgnoreProperties(value = {"handler", "hibernateLazyInitializer"})
public class BaseEntity {

    /**
     * 数据状态
     */
    @Column(name = "obj_status")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    private Integer dataStatus = DataStatusEnum.effective.getCode();

    /**
     * 创建时间
     */
    @Column(name = "obj_createdate")
    @CreatedDate
    @Temporal(TemporalType.DATE)
    @JsonFormat(pattern = "yyyy.MM.dd HH:mm:ss", timezone = "GMT+08:00")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    private Date createDate = new Date();

    /**
     * 创建人
     */
    @CreatedBy
    @Column(name = "obj_createuser")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    private String createUser;

    /**
     * 修改时间
     */
    @Column(name = "obj_modifydate")
    @LastModifiedDate
    @Temporal(TemporalType.DATE)
    @JsonFormat(pattern = "yyyy.MM.dd HH:mm:ss", timezone = "GMT+08:00")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    private Date modifyDate = new Date();

    /**
     * 修改人
     */
    @LastModifiedBy
    @Column(name = "obj_modifyuser")
    @JsonInclude(value = JsonInclude.Include.NON_NULL, content = JsonInclude.Include.NON_NULL)
    private String modifyUser;
}
